<?php
namespace app\data\util;

use think\facade\Config;
use think\facade\Cache;
use think\facade\Db;
/**
 * http头 设置帮助类
 * @Description:
 * @ClassName: HttpUtil
 * @author xx
 * @date 2024-2-26
 */


class HttpUtil{
    /***
     * @return 输出json
     */
    public static function outJson($code=200, $message='' ,$data= [], $break = true) {
        header('Content-type: application/json');
        $arr['code'] = $code;
        $arr['message'] = $message;
        $arr['data'] =  empty($data)?NULL:$data ;
        echo json_encode($arr);
        if ($break) {
            die();
        }
    }
    /***
     * @return 输出jsonp
     */
    public static function outJsonp($code=200, $message='',$data=[], $break=true) {

        $arr['code'] = $code;
        if($arr['code'] > 0){
            $arr['message'] = $message;
        }
        $arr['data'] =  $data ;
        echo $_GET['callback'] . '(' . json_encode($arr) . ')';
        if ($break) {
            die();
        }
    }

    private static function filterNullToStr($v){
        if (is_array($v)) {
            foreach ($v as $k => $a) {
                if (is_array($a)) {
                    $v[$k] = self::filterNullToStr($v[$k]);
                } else {
                    if ($a === null) {
                        $v[$k] = '';
                    }
                    if (is_numeric($a)) {
                        $v[$k] = $a . '';
                    }
                    if (is_bool($a)) {
                        $v[$k] = $a . '';
                    }
                }
            }
        }
        return $v;
    }

    /**
     * @param string $url
     * @return mixed
     */
    public static function doGet($url)
    {
        //初始化
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL,$url);
        // 执行后不直接打印出来
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // 不从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        //执行并获取HTML文档内容
        $output = curl_exec($ch);

        //释放curl句柄
        curl_close($ch);

        return json_decode($output, true);
    }

    /**
     * 使用CURL方式发送get请求
     * @param string $url
     * @param array  $data
     * @return mixed
     */
    public static function doGets($url,$param)
    {
        //初始化
        $ch = curl_init();
        $url= self::urladdparam($url,$param);
        curl_setopt($ch, CURLOPT_URL,$url);
        // 执行后不直接打印出来
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // 不从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        //执行并获取HTML文档内容
        $output = curl_exec($ch);

        //释放curl句柄
        curl_close($ch);

        return json_decode($output, true);
    }
    /**
     * @param string $url
     * @param array $post_data
     * @param array | string $token
     * @return mixed
     */
    public  static function doPost($url, $post_data, $token = '')
    {
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        // 执行后不直接打印出来
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // 设置请求方式为post
        curl_setopt($ch, CURLOPT_POST, true);
        // post的变量
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
        // 请求头，可以传数组
        curl_setopt($ch, CURLOPT_HEADER, false);
        if(!empty($token)){
            $header = ['Accept-Language:zh-CN','authorization:'.$token,'Content-Type:application/x-www-form-urlencoded','charset:utf-8','Accept:application/json','X-APFormat:json'];
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        }
        // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // 不从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        $output = curl_exec($ch);
        curl_close($ch);

        return json_decode($output, true);
    }

    /**
     * 使用CURL方式发送post请求
     * @param  string $url     [请求地址]
     * @param  array  $data    [array格式数据]
     * @return array
     */
    public static function postDataCurl($url, $data){

        $timeout = 5000;

        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt ($ch, CURLOPT_HEADER, false);
        curl_setopt ($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json;']);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); //处理http证书问题
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

        $result = curl_exec($ch);

        if (false === $result) {
            $result =  curl_errno($ch);
        }
        curl_close($ch);
        return self::json_to_array($result) ;
    }

    /**
     * 将json字符串转化成php数组
     * @param  string $json_str
     * @return array $json_arr
     */
    public static function json_to_array($json_str){
        if(is_array($json_str) || is_object($json_str)){
            $json_str = $json_str;
        }else if(is_null(json_decode($json_str))){
            $json_str = $json_str;
        }else{
            $json_str =  strval($json_str);
            $json_str = json_decode($json_str,true);
        }
        if (!is_array($json_str)) {
            return [];
        }
        $json_arr=array();
        foreach($json_str as $k=>$w){
            if(is_object($w)){
                $json_arr[$k]= self::json_to_array($w); //判断类型是不是object
            }else if(is_array($w)){
                $json_arr[$k]= self::json_to_array($w);
            }else{
                $json_arr[$k]= $w;
            }
        }
        return $json_arr;
    }


    /**
     * 组装GET请求参数
     */
    public static function urladdparam($url,$arr=[]){
        if(empty($arr)){
            return $url;
        }
        $arr1=[];
        foreach($arr as $key=>$val){
            $arr1[]=$key."=".$val;
        }
        return rtrim($url,'/').'?'.implode('&',$arr1);
    }



    /**
     * @desc   SHOPIFY接口请求
     */
    public static function getUrl($url, $iscustom = [])
    {
        $apikey       = $iscustom['app_key'];
        $secretapikey = $iscustom['app_secret'];
        $headerArray  = ["Content-Type:application/json;", 'Authorization:Basic ' . base64_encode("$apikey:$secretapikey")];
        $ch           = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }

    /**
     * @desc   airwallex接口请求
     */
    public static function getAirwallexUrlToken($url, $iscustom = [])
    {
        $data = [];
        $id          = $iscustom['merchantId'];
        $apikey      = $iscustom['merchantKey'];
        $headerArray = array("Content-Type:application/json;", 'x-client-id:' . $id, 'x-api-key:' . $apikey);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }


    /**
     * @desc   SHOPIFY接口请求
     */
    public static function postUrl($url, $data = array(), $iscustom = null)
    {

        $data         = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $apikey       = $iscustom['app_key'];
        $secretapikey = $iscustom['app_secret'];

        $headerArray = array("Content-Type:application/json;", 'Authorization:Basic ' . base64_encode("$apikey:$secretapikey"));
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }


    /**
     * @desc   报告接口请求
     */
    public static function tokenPostUrl($url, $data = [],$cookie,$csrf_token = null)
    {
        $cookie = 'master_device_id=59f626b9-5e47-40f2-8fd2-5ff14900e7c7; is_shopify_merchant=1; _y=df987d42-0BE5-4FE5-A811-F73EEF9E8171; _ga=GA1.1.1742766500.1741602086; FPID=FPID2.2.v0pr7%2Fjp7sZUs5wzyzcgidoOIrBxmTF6alXhDO61QrU%3D.1741602086; _fbp=fb.1.1741602286837.530046636120188988; cf_clearance=ikVXuMwU6ppJXTGoxrqLrf4QEkeixe8Up1vzNG5HCPk-1744281705-1.2.1.1-b9SPTUupbAVe5ACcpQmoOumovVVpBTEMftCz4NhutUxl9hKg_LOSC5XjKHxqyPDMOtDZWuJuA6tVHad6FctwXmh9z9SY1lVC6O0SFtlzmhX1XP7LFjTYJGpCW4lveDXpcM72uWRDYAPEuMEjFNXvp95AdF_yCZ4Fst9TlTo_PiOzb2CdBwHG7q3CfukKgisU7yo.I8Eh0wZRvlHcNPzDJau.hso6pk7m8t7EUoWzpEvN8mhTKF4cjmwSjmM5xUoVQqvUPrs4nkyHwI8usbbUdus9IW0_E9E3ZfCo3XcO1.0hxR0.gOi1ySDfFkdVyoTf5jsv_SMFnkv5MSMUni0SheHrwiX1hVEtf6JmveAa2wOQoHpM_ULAJni3G.GNSfzQ; v:a:3=%7B%2298f1a5ee36ee5df0bd49170cc9c7a847%22%3A%7B%22variant%22%3A%22control%22%2C%22createdAt%22%3A1746776975883%7D%2C%2237c27e49804705ffcd2c28824d8060d0%22%3A%7B%22variant%22%3A%22treatment%22%2C%22createdAt%22%3A1747296849052%7D%7D; _ga_W6NECZNE63=GS2.1.s1747296856$o8$g1$t1747302862$j0$l0$h1047821789; logged_in=true; _shopify_essential=bb04cf42-ca78-4252-8dde-2ef33234819c; _shopify_essential_=5e92e954-4aea-457c-b62f-c30fb1529335; cf_clearance=xSGXF1BaH5ZvB8k4yz.Fj3TYCn5LF2bLTv2Ja6knKag-1752140443-1.2.1.1-OIrlCWhmE2omuY25lWVQVrrpioNWr69jEbyX5_W1ydVdS21R9Lj5pxlqE.r0TBDxBgN5WeFAPFCBBu2_.gk7Aaim6Dr34MzguLB01g7qrzT_RUomeuTVzc3CxZWAzlx84R6CwgXNOtwC5ITurhwpdOBSYxDilxWC1fp2MurOGJuuXFfgQI8QP25QjVhq__SX0VifK5CMYwoGi9qNt_0CsMs2ZVS2WYSGTXYo1eYR1R0; _shopify_y=df987d42-0BE5-4FE5-A811-F73EEF9E8171; koa.sid=bJT21MWu2zTI6vpmFs6-7Y-PVylxTaYJ; koa.sid.sig=9iQ16ch04eqMhAKFXmCeXQFGeis; 58760331325--Order--selected-location=%5B%7B%22id%22%3A%22MULTILOCATION_ALL_LOCATIONS_KEY%22%7D%5D; _merchant_essential=%3AAZgxPWlIAAEAUIjoFEFMBlE3igAwVPVshZa97vC41gCDYIOQxJKzXWfeSyCymWk9GpDxsNkdoWNLkGelFR6fDDzpKoZPY6rAy0asL2G6Q3OekDrJUHBh039lzwxXKkZq0o5A1qzM8PMHr8cebgmkhLAlrXdJQcFMCfdeHgwi12UJo6vhhqyY-KB7ew7cLkfJ0ntyX3eodolHxXMMJ_MNUCIEv2JEZTk48lavnz53yfVLttF-PqWAod5Mki2BYxQt-3BgyBYklNzJGIIEqzp7AIWZHyiovrwiip62W717qj0WHpXr--vy3n07iL4UAVIIoGq6udHHdyCX8KjANA1HYOZNNXucgzTt9ndIOXZoJP9Tuz1EJUjcIArdebhA_RGwZE0SKW2WnllJ3THjcUoje-Rl2EW7AIwWQkvYCC1kDRI8I0t-R1tJBMtrr7jxMcc10RLng5m5nNWHvaPYzxqqu9pCo0e993Ae1mZb2egZSwJ2JlrcoK0k80IjzgBT2KJj0wyRnO0FaIQU9YOvYbS1jFu81L2iT2HQc6Go_Ej23zt3DOQ99qZHwByI2sHrBPTIt9l8_k8hNruWdjjY7O6BCnmb1upDRnjpXiEjRB1I0nfRZ5GK_JMDx0Q5OnBqiJz9tkDRv4GrdwkcCDkofdZ0rW2kj9uencdOPE07sCkQMlhnfg%3A; _shopify_s=297a1edb-b748-4d7c-a3aa-5e35158eb6c5';
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray = [
            "Accept: application/json",
            "Content-Type: application/json",
            "x-csrf-token: " . $csrf_token,
            "cookie:". $cookie,
        ];
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }


    /**
     * @desc   shopify接口请求
     * @author luckyXiong
     * @date   2024-09-07
     */
    public static function postUrlShopify($url, $data = array(), $token = null)
    {

        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray = ["Content-Type:application/json;",'X-Shopify-Access-Token:' . $token];
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }


    /**
     * @desc   shopify接口请求
     * @author luckyXiong
     * @date   2024-09-07
     */
    public static function postUrlMaBang($url, $data = array(), $token = null)
    {

        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray = [
                         "Content-Type:application/json;",
                         "X-Requested-With:XMLHttpRequest",
                         'Authorization:' . $token
        ];
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }




    /**
     * @desc   SHOPIFY接口请求
     */
    public static function putUrlShopify($url, $data = array(), $token = null)
    {
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray = ["Content-Type:application/json;",'X-Shopify-Access-Token:' . $token];
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); //设置请求方式
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }



    /**
     * @desc   SHOPIFY接口请求
     */
    public static function getUrlShopify($url,$token = null)
    {

        $headerArray = ["Content-Type:application/json;",'X-Shopify-Access-Token:' . $token];
        $ch           = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }








    /**
     * @desc   SHOPIFY接口请求Shpf辅助插件
     */
    public static function PostUrlShpf($url, $token,$data = array())
    {
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray = array("Content-Type:application/json;", 'Authorization:Bearer '.$token);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
    
    /**
     * @desc   SHOPIFY接口请求
     */
    public static function PostUrlgraphql($url, $access_token, $data = '')
    {
        $data_string = json_encode(['query' => $data]);
        $headerArray = array("Content-Type:application/json;",'X-Shopify-Access-Token:' . $access_token,'Content-Length:' . strlen($data_string));

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        if (curl_errno($curl)) {
            echo 'Errno:' . curl_error($curl);//捕抓异常
        }
        curl_close($curl);
        return $output;
    }
    

    /**
     * @desc   SHOPIFY接口请求
     */
    public static function putUrl($url, $data = array(), $iscustom = array())
    {
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $apikey = $iscustom['app_key'];
        $secretapikey = $iscustom['app_secret'];
        $headerArray = array("Content-Type:application/json;", 'Authorization:Basic ' . base64_encode("$apikey:$secretapikey"));
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); //设置请求方式
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }

    /**
     * @desc   SHOPIFY接口请求
     */
    public static function delUrl($url, $iscustom = array())
    {
        $apikey       = $iscustom['app_key'];
        $secretapikey = $iscustom['app_secret'];
        $headerArray  = ["Content-Type:application/json;", 'Authorization:Basic ' . base64_encode("$apikey:$secretapikey")];
        $ch           = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); //设置请求方式
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }


    public static function  posturlJJS($url, $data)
    {
        $headerArray = array("Content-Type:application/x-www-form-urlencoded;");
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }


    /**
     * @desc   金蚁post接口请求
     * @date   2024-03-16
     * @author luckyXiong
     */
    public static function postUrlJY($url, $data = []){
        //获取金蚁TOKEN
        $token    = Db::name('jinyi_token')->where('id',1)->value('token');
        $data     = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray =["Content-Type:application/json;", 'Cookie:Token=' . $token];
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }


    /**
     * @desc   顺丰post接口请求
     * @date   2024-03-16
     * @author luckyXiong
     */
    public static function postUrlSF($url, $data = [],$type=''){
        //获取顺丰配置
        $confDefault = $type ? 'SFTest' : 'SF';
        $sfInfo = Config::get('Logisticskey.' . $confDefault);
        $appsecret = $sfInfo['appsecret'];
        $appkey    = $sfInfo['appkey'];
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $sign = strtoupper(base64_encode(MD5(($appsecret . $data . $appsecret))));
        $headerArray = ["Content-Type:application/json;", "appKey:" . $appkey, "sign:" . $sign];
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }

    /**
     * @desc   TK广告
     * @date   2024-03-16
     * @author luckyXiong
     */
    public static function getUrlTk($url, $access_token){
        $headerArray = array('Access-Token:' . $access_token);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    /**
     * @desc   FB广告
     * @date   2024-03-16
     * @author luckyXiong
     */
    public static function getUrlFB($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    /**
     * @desc   贝宝争议
     * @date   2024-03-16
     * @author zhangheng
     */
    public static function getUrlPaypal($url,$api){
        $apikey = $api['apikey'];
        $apisecret = $api['apisecret'];
        $headerArray = array("Content-Type:application/x-www-form-urlencoded;", 'Authorization:Basic ' . base64_encode("$apikey:$apisecret"));
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }


    
    /**
     * @desc   Stripe争议
     * @date   2024-08-20
     * @author zhangheng
     */
    public static function getUrlStripe($url,$api){
        $api = $api['apikey'];
        $headerArray = array("Content-Type:application/json;", 'Authorization:Bearer '.$api);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }
    

    /**
     * @desc   实时汇率
     * @date   2024-08-20
     * @author zhangheng
     */
    public static function getUrlEx($url)
    {
        $ch           = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }


    /**
     * @desc   SHOPIFY接口请求
     */
    public static function getUrlshopline($url, $iscustom = [])
    {
        $apisecret = $iscustom['app_secret'];
        $headerArray = array("Content-Type:application/json;", 'Authorization:Bearer ' . $apisecret);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }



    /**
     * @desc  FeiShu接口请求
     *
     */
    public static function postFeiShu($url, $token,$data = array())
    {
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray = array("Content-Type:application/json;", 'Authorization:Bearer '.$token);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }




    /**
     * @desc  FeiShu接口请求GET
     *
     */
    public static function getFeiShu($url, $token)
    {
        $headerArray = ['Authorization:Bearer '.$token];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }




    /**
     * @desc  17track物流商接口请求POST
     * @date  2024-03-16
     * @author luckyXiong
     */
    public static function trackPostUrl($url, $data =[]){
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray = array("Content-Type: application/json; charset=utf-8", "17token:3273EB49B593024FA918CA49E12699A5");
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }

    /**
     * @desc  718物流商接口请求POST
     * @date  2025-03-16
     * @author zhangheng
     */
    public static function trackPostUrl718($url, $data =[]){
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray = array("Content-Type: application/json; charset=utf-8", "Track718-API-Key: 3a1f5a30-7370-11f0-a568-0383743f6bd8");
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }

    /**
     * @desc  客服--reamaze消息会话
     * @date  2024-11-01
     * @author zhagnheng
     */
    public static function getUrlReamaze($url, $iscustom = []){
        $email       = $iscustom['email'];
        $token = $iscustom['token'];
        $headerArray  = ["Content-Type:application/json;", 'Authorization:Basic ' . base64_encode("$email:$token")];
        $ch           = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }
    /**
     * @desc  客服--reamaze消息会话
     * @date  2024-11-01
     * @author zhagnheng
     */
    public static function putUrlReamaze($url, $data = array(), $iscustom = array())
    {
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $email       = $iscustom['email'];
        $token = $iscustom['token'];
        $headerArray  = ["Content-Type:application/json;", 'Authorization:Basic ' . base64_encode("$email:$token")];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); //设置请求方式
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }

    /**
     * @desc  客服--reamaze消息会话
     * @date  2024-11-01
     * @author zhagnheng
     */
    public static function postUrlReamaze($url, $data = array(), $iscustom = array())
    {
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $email       = $iscustom['email'];
        $token = $iscustom['token'];
        $headerArray  = ["Content-Type:application/json;", 'Authorization:Basic ' . base64_encode("$email:$token")];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output, true);
    }


    /**
     * @desc  谷歌广告
     * @date  2024-03-16
     * @author zhangheng
     */
    public static function postUrlgg($url, $data =[], $iscustom = []){
        $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $access_token = $iscustom['access_token'] ?? '';
        $developer_token = $iscustom['developer_token'] ?? '';
        $login_customer_id = $iscustom['login_customer_id'] ?? '';
        $headerArray = [
            'Content-Type:application/json',
            'login-customer-id:'.$login_customer_id,
            'Authorization:Bearer '.$access_token,
            'developer-token:'.$developer_token,
        ];
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }

    /**
     * @desc   易境通post接口请求
     * @date  2024-12-07
     * @author zhangheng
     */
    public static function postUrlYiJT($url, $data = []){
        //获取金蚁TOKEN
        $data     = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray =["Content-Type:application/json;"];
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }

    /**
     * @desc   1688post接口请求
     * @date  2025-01-07
     * @author zhangheng
     */
    public static function alibabapost($url, $data,$signature){
        //获取金蚁TOKEN
        $data     = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
        $headerArray  = [
            "Content-Type:application/json;", 
            "_aop_signature:".$signature, 
            "signature:".$signature, 
            'access_token:4ec40e2c-6616-4387-8e8e-844c4b8497e7',
        ];
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        $output = json_decode($output,true);
        return $output;
    }

}